<style>
  #etlDatafile {
    display: none;
  }
</style>
<template>
  <Modal v-model="showModal" width="1100" :mask-closable="false" :closable="false">
    <Form ref="applyInfo" :rules="applyValidate" :model="handleInfo" :label-width="140" label-position="left"
      class="form form_left">
      <div
        v-if="(waitTasks.isEdit == 16 || waitTasks.isEdit == 17) && (serviceType === 'resourceAllo'  || serviceType === 'entry' || serviceType == 'resource_resourceSon') ">
        <component
          v-if="waitTasks.isEdit == 16 && (serviceType === 'resourceAllo' || serviceType == 'resource_resourceSon')"
          ref="resourceInfo" :is="'resourceInfo'" :isEdit="isEdit" :handleInfo="true" :dataInfo="dataInfo"
          :waitTaskInfo="waitTasks" :serviceType="serviceType" :editNumber="true"></component>
        <component v-else-if="waitTasks.isEdit == 16" ref="resourceInfo" :is="'resourceInfo'" :isEdit="isEdit"
          :handleInfo="true" :dataInfo="dataInfoChange.find(e => e.taskId == waitTasks.taskId)"
          :waitTaskInfo="waitTasks" :serviceType="serviceType" :editNumber="true"></component>
        <template v-else-if="waitTasks.isEdit == 17">
          <div v-for="dataItem in allDataInfo">
            <component ref="resourceInfo" :is="'resourceInfo'" :isEdit="isEdit" :handleInfo="true" :dataInfo="dataItem"
              :waitTaskInfo="waitTasks" :serviceType="serviceType" :editNumber="true"></component>
          </div>
        </template>
      </div>
      <div
        v-else-if="waitTasks.isEdit == 5  || waitTasks.isEdit ==7  || waitTasks.isEdit == 9 || waitTasks.isEdit == 13 || waitTasks.isEdit == 14 || serviceType === 'severMachine'
        || serviceType === 'entry' || (serviceType === 'resourceAllo' && taskDefKey == '_3' && (dataInfo.toolList.length > 0 || dataInfo.resourceList.length > 0))">
        <component ref="resourceInfo" :is="'resourceInfo'" :isEdit="isEdit"
          :handleInfo="taskDefKey =='_09' || taskDefKey =='_10' || taskDefKey =='_16'? true:false" :dataInfo="dataInfo"
          :waitTaskInfo="waitTasks" :serviceType="serviceType"
          :editNumber="waitTasks.isEdit == 16  || waitTasks.isEdit == 5 || waitTasks.isEdit == 7 || waitTasks.isEdit == 9 || waitTasks.isEdit == 13 ||
           (serviceType === 'resourceAllo' && taskDefKey == '_3') || (serviceType === 'entry' && (taskDefKey == '_07sonresource' || taskDefKey == '_15sontool')) ? true:false">
        </component>
      </div>
      <div v-if="isEdit == 24 ">
        <component ref="resourceInfo" :is="'resourceInfo'" :isEdit="isEdit" :handleInfo="true" :dataInfo="dataInfo"
          :waitTaskInfo="waitTasks" :serviceType="serviceType" :editNumber="true"></component>
      </div>

      <div v-if=" waitTasks.isEdit == 20">
        <Row>
          <Col span="8">
          <FormItem label="实际分配团队名称：">
            <Input v-model="openApiInfo.fanTeamName" />
            <!-- <Select v-model="openApiInfo.fanTeamName" :transfer="true" placeholder="搜索团队名称" label-in-value
              @on-change="getApiServListByFanTeam" filterable :remote-method="seachAllTeamList"
              :loading="loadingFanTeamName">
              <Option v-for="(i,index) in teamList" :value="i.teamName" :key="index">{{i.label}}</Option>
            </Select> -->
          </FormItem>
          </Col>
          <Col span="8">
          <FormItem label="实际分配团队标识：">
            <Input v-model="openApiInfo.fanTeamLabel" />
          </FormItem>
          </Col>
        </Row>
        <component ref="resourceInfo" :is="'resourceInfo'" :isEdit="isEdit" :handleInfo="true" :dataInfo="dataInfo"
          :waitTaskInfo="waitTasks" :serviceType="serviceType" :editNumber="true"></component>
      </div>

      <div v-if="isEdit == 22">
        <Row>
          <Col span="20">
          <FormItem label="数据列表：">
            <Row>
              <Col span="8">
              <Button type="primary" size="small" @click="addEtlDataList">新增</Button>
              <Button type="primary" size="small" @click="clickEtl">导入</Button>
              <input type="file" id="etlDatafile" @change="importData" />
              <a href="./static/file_mould/ETLDataModel.xlsx" class="download_boder"
                style="font-size: 13px;margin-left: 10px;top: 6px; position: relative;font-weight: normal;">数据模板</a>
              </Col>
            </Row>
            <Row>
              <Col span="24">
              <Table border :columns="etlDataColumns" :data="etlDataList">
                <template slot-scope="{ row, index }" slot="dataName">
                  <Input v-model="etlDataList[index].dataName" />
                </template>
                <template slot-scope="{ row, index }" slot="action">
                  <Button type="error" @click="removeEtlDataList(index)" size="small"
                    :disabled="(etlDataList.length==1)">删除</Button>
                </template>
              </Table>
              <div v-if="etlTotal > 10" style="float: right;margin: 10px;">
                <Page :current="etlPage" :total="etlTotal" :page-size="etlTotalPageSize" show-total
                  @on-change="changeEtlPage"></Page>
              </div>
              </Col>
            </Row>
          </FormItem>
          </Col>
        </Row>
      </div>

      <div v-if=" waitTasks.isEdit == 10  || waitTasks.isEdit == 14 ">
        <component ref="sonAccount" :is="'sonAccount'" :myAccount="myAccount" :page="'accountHandle'"
          :serviceType="serviceType" :taskDefKey="taskDefKey" :ifedit="true" :isEdit="waitTasks.isEdit"></component>
      </div>
      <div v-if="serviceType==='vip' && operation==='yes' && isEdit==4">
        <div style="padding-bottom: 10px">
          <span>请填写浮动IP：</span>
        </div>
        <div style="margin-bottom:1rem" v-for="(item, index) in objList" :key="index">
          <vipTable ref="vipTable" v-model="objList[index]" :ifedit="true" :isHandle="true"></vipTable>
        </div>
        <!-- <vipTable ref="vipTable" v-model="processInfo.content" :ifedit="true" :isHandle="true"></vipTable> -->
      </div>

      <div v-if="serviceType==='netmapping' && operation==='yes' && isEdit==18">
        <Table :columns="netMapColumns" :data="netmapobject" border>

          <template slot-scope="{ row, index }" slot="ip">
            <p>{{netmapobject[index].ip}}</p>
            <!-- <Input v-else v-model="netmapobject[index].ip"  :readonly="ifedit" /> -->
          </template>

          <template slot-scope="{ row, index }" slot="serverType">
            <p>{{netmapobject[index].serverType}}</p>
            <!-- <Select v-else v-model="netmapobject[index].serverType" :disabled="ifedit" :transfer='true' style="z-index:99999">
							<Option value="裸金属服务器">裸金属服务器</Option>
							<Option value="vip">vip</Option>
							<Option value="负载均衡">负载均衡</Option>
						</Select> -->
          </template>

          <template slot-scope="{ row, index }" slot="mapIp">
            <div v-if="isEdit!=18 && netmapobject[index].mapIp==''">
              <p>{{'网络接口人填写'}}</p>
            </div>
            <div v-else>
              <p v-if="isEdit!=18">{{netmapobject[index].mapIp}}</p>
              <Input v-else v-model="netmapobject[index].mapIp" @on-blur="checkIP(netmapobject[index].mapIp,index)"
                :readonly="isEdit!=18" />
            </div>

          </template>

          <!-- <template slot-scope="{ row, index }" slot="action">
						<Button v-if="!ifedit" @click="deleteRow(row, index)">删除</Button>
					</template> -->
        </Table>
      </div>

      <!-- 采集交换处理 -->
      <div v-if="isEdit == 21">
        <Row>
          <Col span="8">
          <FormItem label="采集数据目录：">
            <Input v-model="dataEtlInfo.etlPath" />
          </FormItem>
          </Col>
          <Col span="8" class="col_left">
          <FormItem label="ETL帐户：">
            <Input v-model="dataEtlInfo.etlAccount" />
          </FormItem>
          </Col>
        </Row>
        <component ref="resourceInfo" :is="'resourceInfo'" :isEdit="isEdit" :handleInfo="true" :dataInfo="dataInfo"
          :waitTaskInfo="waitTasks" :serviceType="serviceType" :editNumber="true"></component>
      </div>
      <Row>
        <Col span="20">
        <FormItem label="执行操作：">
          <RadioGroup v-model="operation" @on-change="getHandleUserInfo">
            <template v-for="item in operationList">
              <Radio style="font-size:13px" :label="item.msgType">{{item.name}}</Radio>
            </template>
          </RadioGroup>
        </FormItem>
        </Col>
      </Row>
      <Row v-show=" handleName.length > 0">
        <Col span="20">
        <FormItem :label="utils.objectIsEmpty(nextCanInfo.name) ? '下一步处理人员': nextCanInfo.name + '：'">
          <Select v-if="operation == 'sign'" v-model="handleInfo.signIds" filterable clearable
            :multiple="operation == 'sign'" @keydown.native.enter.prevent>
            <Option v-for="(item, i) in handleName" :value="item.id" :key="i" :label="item.user_name">
              <span>{{item.user_name + (item.isleader == 1 ? "(领导)":'')}}</span>
              <li v-for="i in item.structs " style="margin-left: 10px;font-size:10px; color:#c5c8ce;">
                {{i.gName + (i.isleader == 1 ? "(领导)":'')}}
              </li>
            </Option>
          </Select>
          <Select v-else v-model="handleInfo.nextOperator.id" filterable clearable @keydown.native.enter.prevent
            @on-change="setNextOperator">
            <Option v-for="(item, i) in handleName" :value="item.id" :key="i" :label="item.user_name">
              <span>{{item.user_name + (item.isleader == 1 ? "(领导)":'')}}</span>
              <li v-for="i in item.structs " style="margin-left: 10px;font-size:10px; color:#c5c8ce;">
                {{i.gName + (i.isleader == 1 ? "(领导)":'')}}
              </li>
            </Option>
          </Select>
        </FormItem>
        </Col>
      </Row>
      <Row v-show=" !utils.objectIsEmpty(nextCanInfo.remark)">
        <Col span="20">
        <FormItem label="备注: ">
          <span>{{nextCanInfo.remark}}</span>
        </FormItem>
        </Col>
      </Row>
      <!-- <Row v-if="operation == 'yes'">
				<Col span="20">
				<FormItem v-if="(serviceType === 'register' && taskDefKey === '_3')" label="赋予账号:" prop="user_number">
					<Poptip content="用户账号只能是字母、数字和下划线,且长度在5-20之间!">
						<Input v-model="handleInfo.user_number" />
					</Poptip>
				</FormItem>
				</Col>
			</Row>
			<Row v-if="operation == 'yes'">
				<Col span="20">
				<FormItem v-if="(serviceType === 'register' && taskDefKey === '_3')" label="组织架构:" prop="structs">
					<Select v-model="handleInfo.structs" placeholder="搜索或下拉选择" filterable multiple>
						<Option v-for="item in structList" :value="item.id" :key="item.id">{{item.gName}}</Option>
					</Select>
				</FormItem>
				</Col>
			</Row>
			<Row v-if="operation == 'yes'">
				<Col span="20">
				<FormItem v-if="(serviceType === 'register' && taskDefKey === '_3')" label="关联角色:">
					<Select v-model="handleInfo.roles" placeholder="搜索或下拉选择" filterable multiple>
						<Option v-for="item in roleList" :value="item.id" :key="item.id">{{item.role_name}}</Option>
					</Select>
				</FormItem>
				</Col>
			</Row>
			<Row v-if="operation == 'yes'">
				<Col span="20">
				<FormItem v-if="(serviceType === 'register' && taskDefKey === '_3')" label="关联租户:">
					<Select v-model="handleInfo.tenants" placeholder="搜索或下拉选择" filterable multiple>
						<Option v-for="item in tenantList" :value="item.id" :key="item.id">{{item.tenant_name}}</Option>
					</Select>
				</FormItem>
				</Col>
			</Row> -->
      <Row>
        <Col span="20">
        <FormItem label="处理意见:" prop="message">
          <Input v-model="handleInfo.message" type="textarea" :autosize="{minRows: 4,maxRows: 6}" />
        </FormItem>
        </Col>
      </Row>
      <Row v-if="filesList != null && filesList.length > 0">
        <Col span="24" class="Col_height" style="position: relative;">
        <FormItem label="附件模板:">
          <fileDownload2 :files="filesList"></fileDownload2>
        </FormItem>
        <Spin size="large" fix v-if="loadingFile" style="font-size: 10px">正在下载附件...</Spin>
        </Col>
      </Row>
      <Row>
        <Col span="24">
        <span
          v-if="(waitTasks.isPrint == '1' || (serviceType==='hightAuthoritys' && taskDefKey==='_03') || (serviceType==='entry' && taskDefKey==='_04')) && handleInfo.files.length == 0 && handleInfo.operation != 'no'"
          style="font-size: 13px; color: red;">请上传领导签字材料</span>
        <fileUpload ref="fileUpload" :fileType="'req_appendix'" v-model="handleInfo.files"></fileUpload>
        </Col>
      </Row>
    </Form>
    <div slot="footer">
      <Button v-if="!handleLoading" @click="showModal = false;handleLoading = false">取消</Button>
      <Button type="primary" :loading="handleLoading" @click="submintHandle()">提交</Button>
    </div>
  </Modal>
</template>
<script>
  import Axios from 'axios'
  import ajax from "../../ajax_util"
  import fileUpload from '../../base/file_uploader'
  import resourceInfo from './resource_info'
  import sonAccount from '../applyVue/account/sonAccount'
  import fileDownload2 from '../../base/file_download2.vue'
  import vipTable from '../applyVue/vip/vip_table.vue'
  import excel from "../../utils/excel";

  export default {
    name: "handleModal",
    components: {
      fileUpload,
      resourceInfo,
      sonAccount,
      fileDownload2,
      vipTable
    },
    data() {
      const validateusernumber = (rule, value, callback) => {
        if (this.handleInfo.user_number == '') {
          callback(new Error('请赋予账号名称'));
        } else if (this.handleInfo.user_number != '') {
          let reg = /^[A-Za-z0-9_]{5,20}$/;
          if (!reg.test(this.handleInfo.user_number)) {
            callback(new Error('用户账号格式不规范!'));
          } else {
            var url = this.CONFIG.url_know + '/repeat-number/' + this.handleInfo.user_number;
            var that = this;
            this.utils.delay(() => {
              ajax.get({
                url: url,
                that: that,
                success: function(data) {
                  console.log('date', data)
                  if (data == '0') {
                    callback(new Error('已存在该名称！请重新填写'));
                  } else {
                    callback()
                  }
                }
              })
            }, 300)
          }
        }
      };
      return {
        etlTotalPageSize: 5,
        etlPage: 1,
        etlTotal: 0,
        etlDataList: [],
        allEtlDataList: [], //所有的表数据
        etlDataColumns: [{
            title: "序号",
            type: 'index',
            width: 80,
            align: 'center'
          },
          {
            title: '表名',
            key: "dataName",
            align: 'center',
            slot: "dataName"
          },
          {
            title: '操作',
            slot: 'action',
            width: 80,
            align: 'center'
          }
        ],
        teamList: [], // 开放平台团队集合
        loadingFanTeamName: false,
        openApiInfo: { //处理阶段需要填写的数据
          fanTeamName: "",
          fanTeamLabel: ""
        },
        dataEtlInfo: {
          etlPath: "",
          etlAccount: "",
        },
        IP_CHECK: [],
        loadingFile: false,
        filesList: [],
        handleLoading: false,
        handleName: [], //处理人员列表
        nextCanInfo: {
          name: "下一步处理人员"
        }, // 获取下一步处理人的信息
        operation: "", //执行
        lastOperation: "", //上一个执行操作
        handleInfo: {
          taskDefKey: "",
          content: {},
          reqId: "",
          taskId: "",
          message: "",
          user_number: "",
          roles: [],
          tenants: [],
          structs: [],
          operation: "",
          nextOperator: {
            id: "",
            userName: ""
          },
          signIds: [],
          files: []
        },
        roleList: [],
        tenantList: [],
        structList: [],
        applyValidate: {
          message: [{
              required: true,
              message: '请填写意见',
              trigger: 'change'
            },
            {
              type: 'string',
              max: 1950,
              message: '最多填写1950个字符',
              trigger: 'blur'
            }
          ],
          user_number: [{
            required: true,
            validator: validateusernumber,
            trigger: 'change'
          }],
          structs: [{
            required: true,
            type: 'array',
            min: 1,
            message: '请选择组织架构',
            trigger: 'change'
          }],
        },
        dataInfo: this.$parent.dataInfo,
        dataInfoChange: this.$parent.dataInfoChange,
        allDataInfo: this.$parent.allDataInfo,
        reqId: this.$parent.reqId,
        serviceType: this.$parent.serviceType,
        waitTasks: this.$parent.waitTasks,
        taskDefKey: this.$parent.taskDefKey,
        isDelegate: this.$parent.isDelegate,
        tabs: {},

        myAccount: this.processInfo,
        todo_ser: 0,
        todo_db: 0,
        todo_hadoop: 0,
        todo_uap: 0,
        todo_paas: 0,
        todo_dacp: 0,
        todo_else: 0,
        myObject: {}, // 账号申请
        accountInfo: {},
        content: {},

        columns: [{
            title: '浮动IP',
            slot: 'ip'
          },
          {
            title: '备注',
            slot: 'des'
          },
          {
            slot: 'action',
            align: 'center',
            renderHeader: (h, index) => {
              return h('div', [
                h(!this.ifedit ? 'Button' : "", {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  on: {
                    click: () => {
                      if (!this.ifedit) {
                        this.addRow()
                      }
                    }
                  }
                }, !this.ifedit ? '新增' : "")
              ])
            }
          }
        ],
        // netmapobject:[{
        //         'ip':'',
        //         'serverType':'',
        //         'mapIp':'',
        // }],
        netmapobject: "",
        netMapColumns: [{
            title: "ip",
            align: "center",
            width: 150,
            key: "ip",
            slot: "ip",
            // fixed: 'left'
          },
          {
            title: "主机类型",
            align: "center",
            width: 150,
            key: "serverType",
            slot: "serverType",
          },
          {
            title: "映射ip",
            align: "center",
            // width: 140,
            key: "mapIp",
            slot: "mapIp",
          },
          // {
          // 	slot: 'action',
          // 	align: 'center',
          // 	width: 150,
          // 	// fixed: 'right',
          // 	renderHeader: (h, index) => {
          // 		return h('div', [
          // 		h(!this.ifedit ? 'Button' : "", {
          // 			props: {
          // 			type: 'primary',
          // 			// size: 'small'
          // 			},
          // 			on: {
          // 			click: () => {
          // 				if (!this.ifedit) {
          // 				this.addRow()
          // 				}
          // 			}
          // 			}
          // 		}, !this.ifedit ? '新增' : "")
          // 		])
          // 	}
          // },
        ],
        // vip
        object: [],
        objList:[
              [{
                  des: "",
                  id: 0,
                  ip: "",
                  overId: 0,
                  ipFlag:false,
                  ipGroup:1,
              }]
          ],
        operationList: [] // 执行操作集合
      }
    },
    mounted: function() {
      console.log("========taskDefKey==========", this.taskDefKey);
      console.log("99999999999", this.processInfo);
      if (this.processInfo.content != null) {
        this.netmapobject = this.processInfo.content.strategies
      }
      if (this.serviceType === 'vip') {
        this.objList = this.classify(this.processInfo.content,'ipGroup')
      }
      // if (this.serviceType === 'register' && this.taskDefKey === '_3') {
      // 	this.getTenants();
      // }
    },
    methods: {
      classify(arr, key) {
          let kind = []; //存放属性标识
          let newArr = []; //返回的数据
          arr.map((item) => {
              // 判断key是否存在，不存在则添加
              if (!kind.includes(item[key])) {
              kind.push(item[key]); //kind添加新标识
              newArr.push([]); //添加数组
              }
              let index = kind.indexOf(item[key]); //返回带有标识在kind内的下标，判断加入哪个数组
              newArr[index].push(item); //将对象存入数组
          });
          return newArr;
      },
      /**
       * 获取Etl的Path
       */
      getHistoryEtlPath() {
        var that = this;
        var url = this.CONFIG.progress_url + '/sp-etl-tool/history/etl-path';
        var params = {
          projectId: ""
        }
        ajax.get({
          url: url,
          that: that,
          params: params,
          success: function(data) {

          }
        })
      },
      changeEtlPage(page) {
        this.etlPage = page
        var pageNumber = page * this.etlTotalPageSize
        if (pageNumber > this.etlTotal) {
          this.etlDataList = this.allEtlDataList.slice((page - 1) * this.etlTotalPageSize, this.etlTotal)
          console.log("this.etlDataList = ", page, this.etlTotal, this.etlDataList)
        } else {
          this.etlDataList = this.allEtlDataList.slice((page - 1) * this.etlTotalPageSize, pageNumber)
        }

        this.$forceUpdate()
      },
      clickEtl() {
        const el = document.getElementById("etlDatafile");
        el.click();
      },
      addEtlDataList() {
        this.allEtlDataList.push({
          dataName: ""
        })
        this.etlTotal = this.allEtlDataList.length
        this.changeEtlPage(parseInt(this.allEtlDataList.length / this.etlTotalPageSize) + 1)
      },
      /**
       * 导入模板
       */
      async importData() {
        const el = document.getElementById("etlDatafile");
        const file = el.files[0];
        var that = this

        var columns = [{
          title: "表名",
          key: "dataName"
        }]
        var data = await excel.importFromLocal(file);
        var c = 0
        data.body.forEach(item => {
          if (this.allEtlDataList.findIndex(e => e.dataName === item.dataName) != -1) {
            c += 1
          }
          this.allEtlDataList.push({
            dataName: item.dataName
          })
        })
        this.etlTotal = this.allEtlDataList.length
        this.changeEtlPage(1)
        this.$forceUpdate()
        that.$Notice.success({
          title: '导入成功!' + (c == 0 ? '' : ('发现多条数据重复!')),
        });
        el.value = "";
      },
      /**
       * 删除etl数据表
       * @param {Object} index
       */
      removeEtlDataList(index) {
        this.allEtlDataList.splice(index + (this.etlPage - 1) * this.etlTotalPageSize, 1);
        this.etlTotal = this.allEtlDataList.length
        this.changeEtlPage(this.etlPage)
      },
      /**
       * 搜索开发平台团队
       * @param {Object} queryCond
       */
      seachAllTeamList(queryCond) {
        this.teamList = []
        this.loadingFanTeamName = true
        this.utils.delay(() => {
          var that = this
          var params = {
            queryCond: queryCond
          }
          this.myAjax.get({
            url: this.CONFIG.progress_url + '/open-api-platform/getAllTeamList',
            that: that,
            params: params,
            success: function(data) {
              that.teamList = data
              that.$nextTick(() => {
                that.loadingFanTeamName = false
              })
            }
          })
        }, 500)
      },
      /**
       * 设置开放平台处理时分配团队信息
       * @param {Object} value
       */
      getApiServListByFanTeam(value) {
        if (value) {
          this.openApiInfo.fanTeamLabel = value.label
        }
      },
      checkIP(data, index) {
        var result = ''
        console.log('checkIP', data)
        if (data === '') {
          this.$Message.error('请输入映射IP！')
        }
        console.log("====data====", data);
        let ipRegex =
          /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
        if (ipRegex.test(data) === false) {
          this.$Message.error('输入映射IP格式有误，请重新输入！')
          result = false
        } else {
          this.$Message.success('输入映射IP格式正确')
          result = true
        }
        this.IP_CHECK[index] = result
      },
      checkVIP(data, index) {
        console.log("====data====", data);
        let ipRegex =
          /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
        if (ipRegex.test(data) === false) {
          this.$Message.error('输入IP格式有误，请重新输入！')
          this.object[index].ipFlag = true;
        } else {
          this.object[index].ipFlag = false;
        }
      },
      //获取租户
      getTenants() {
        var that = this;
        var url = this.CONFIG.url_know + '/listTenants';
        ajax.get({
          url: url,
          that: that,
          success: function(data) {
            //console.log("=========",data);
            that.tenantList = data;
            that.getRoles();
          }
        })
      },

      //获取可关联角色
      getRoles() {
        var u_id = this.$store.state.user.id;
        var that = this;
        var url = this.CONFIG.url_know + '/get-edit-roles/' + u_id;

        ajax.get({
          url: url,
          that: that,
          success: function(data) {
            //console.log("=========",data);
            that.roleList = data;
            that.getStruct();
          }
        })
      },

      //获取组织结构
      getStruct() {
        var that = this;
        var url = this.CONFIG.url_know + '/getAllStructs';
        ajax.get({
          url: url,
          that: that,
          success: function(data) {
            //console.log("=========",data);
            that.structList = data;
          }
        })
      },

      //提交处理结果
      submintHandle() {
        this.handleLoading = true
        var check_ip = true
        if (this.IP_CHECK.length > 0) {
          this.IP_CHECK.forEach(item => {
            if (item == false) {
              check_ip = false
            }
          })
        }
        var isEtlInfo = true //是否填写数据采集交换工具基本信息
        var isEtlMassge = ""
        if (this.isEdit == 23 && this.operation == "yes") {
          if (this.$parent.$refs.apply.toolInfo.toolList && this.$parent.$refs.apply.toolInfo.toolList.length > 0) {
            this.$parent.$refs.apply.toolInfo.toolList.some(item => {
              item.toolList.some(tool => {
                if (tool.spServiceType == "dataEtl" && tool.check && tool.spContent.ifNeedPublicData == 1) {
                  if (tool.spContent.publicTransmisMode == "[]") {
                    isEtlInfo = false
                    isEtlMassge = "请填写数据采集交换工具中的 “公有数据-传输方式”"
                  } else if (!tool.spContent.publicMemory) {
                    isEtlInfo = false
                    isEtlMassge = "请填写数据采集交换工具中的 “公有数据-存储数据量”"
                  } else if (!tool.spContent.publicPurpose) {
                    isEtlInfo = false
                    isEtlMassge = "请填写数据采集交换工具中的 “公有数据-测算依据”"
                  } else if (!tool.spContent.encryption) {
                    isEtlInfo = false
                    isEtlMassge = "请填写数据采集交换工具中的 “安全加密要求”"
                  } else if (!tool.spContent.isSafe) {
                    isEtlInfo = false
                    isEtlMassge = "请填写数据采集交换工具中的 “是否通过安全审批”"
                  } else if (!tool.spContent.etlTool) {
                    isEtlInfo = false
                    isEtlMassge = "请选择数据采集交换工具中的 “ETL工具”"
                  }
                  return true
                }
              })
            })
          }
        }
        if (isEtlInfo) {
          if (check_ip) {
            this.$refs['applyInfo'].validate((valid) => {
              if (valid) {
                var url = ""
                var that = this

                if (that.handleInfo.operation === 'end') {
                  var temp = {
                    content: {},
                    reqId: this.reqId,
                    taskId: this.waitTasks.taskId,
                    message: this.handleInfo.message,
                    operation: "end"
                  }
                  url = this.CONFIG.base_url_test + "/process"

                  ajax.put({
                    url: url,
                    that: that,
                    data: temp,
                    success: function() {
                      that.submintSuccess("关闭成功！")
                    }
                  })
                } else {
                  if (this.validateSubmintInfo()) {
                    this.setResourceSubmit()

                    this.$parent.$refs.apply.getHandleParams(this.handleInfo)

                    //处理模型的公共参数
                    that.handleMessage(this.operation)
                    // if (this.serviceType === 'register' && this.taskDefKey === '_3' && this.handleInfo.user_number != "") {
                    // 	that.handleInfo.message += ";赋予账号: " + this.handleInfo.user_number
                    // }
                    that.handleInfo.reqId = that.reqId
                    that.handleInfo.taskId = that.waitTasks.taskId
                    that.handleInfo.taskDefKey = that.waitTasks.task_def_key

                    if (that.isDelegate == 1) { //处理委派
                      that.handleInfo.id = that.waitTasks.delegateList[that.waitTasks.delegateList.length - 1].id
                    }
                    that.handleInfo.message = JSON.parse(JSON.stringify(that.handleInfo.message))
                    console.log("handleInfo-------->", JSON.stringify(that.handleInfo))
                    url = that.CONFIG.base_url_test + "/process"
                    // that.handleLoading = false
                    ajax.put({
                      url: url,
                      that: that,
                      data: that.handleInfo,
                      success: function() {
                        that.submintSuccess("处理成功！")
                      },
                      err: function(data) {
                        that.handleLoading = false
                      }
                    })
                  } else {
                    this.handleLoading = false
                  }
                }
              } else {
                this.$Message.error('请填写必填项！');
                this.handleLoading = false
              }
            })
          } else {
            this.$Message.error('请正确填写映射ip！');
            this.handleLoading = false
          }
        } else {
          this.$Message.error({
            content: isEtlMassge,
            duration: 5
          });
          this.handleLoading = false
          this.showModal = false
          this.$parent.$refs.apply.stepTitleId = 2
        }

      },
      //设置资源相关的信息
      setResourceSubmit() {
        // 处理账号相关
        if (this.waitTasks.isEdit == 10 && this.handleInfo.operation === 'yes') {
          this.submintSubAccount();
          this.handleInfo.content.object = this.myObject;
        }
        // 处理vip相关
        if (this.operation === "yes" && this.waitTasks.isEdit == 4) {
          console.log("======getVIP=======",this.object);
          this.handleInfo.content.object = this.object;
          this.handleInfo.content.files = this.handleInfo.files;
        }
        //网络映射
        if (this.operation === "yes" && this.waitTasks.isEdit == 18) {
          // console.log('this.netmapobject',this.netmapobject)
          // this.handleInfo.content.object = this.netmapobject;
          var temp = []
          this.netmapobject.forEach(item => {
            temp.push({
              'id': item.id,
              'mapIp': item.mapIp
            })
          })
          this.handleInfo.content.object = temp
        }
        // 资源相关
        var temp = []
        // 兼容老版本，判断加到最前面
        if (this.waitTasks.isEdit == 16 && (this.serviceType == 'resource_resourceSon' || this.serviceType ==
            'resourceAllo')) {
          if (this.dataInfo.severList.length > 0) {

            this.dataInfo.severList.some(item => {
              if (item.check) {
                var t = {
                  alloId: item.id,
                  quantity: item.quantitys,
                  serviceId: item.severId
                }
                temp.push(t)
              }
            })
          } else {
            var resource = []
            var tool = []
            var data = this.dataInfo
            this.setResource(data, resource, tool)
            var temp2 = {
              resource: resource,
              tools: tool
            }

            this.$set(this.handleInfo.content, "object", temp2)
            console.log("---2->", this.handleInfo.content)
          }
        } else if (this.waitTasks.isEdit == 16) {
          if (this.dataInfo.severList.length > 0) {

            this.dataInfo.severList.some(item => {
              if (item.check) {
                var t = {
                  alloId: item.id,
                  quantity: item.quantitys,
                  serviceId: item.severId
                }
                temp.push(t)
              }
            })
          } else {
            var resource = []
            var tool = []
            var data = this.dataInfoChange.find(e => e.taskId == this.waitTasks.taskId)
            this.setResource(data, resource, tool)
            var temp2 = {
              resource: resource,
              tools: tool
            }
            this.$set(this.handleInfo.content, "object", temp2)
            console.log("---2->", this.handleInfo.content)
          }
        } else if (this.waitTasks.isEdit == 17) {
          var resource = []
          var tool = []
          this.allDataInfo.forEach(data => {
            this.setResource(data, resource, tool)
          })

          var temp2 = {
            tools: tool,
            resource: resource
          }
          this.$set(this.handleInfo.content, "object", temp2)
        } else if (this.waitTasks.isEdit == 5 || (this.waitTasks.task_def_key == "_07sonresource" && this
            .serviceType === 'entry')) {
          var resource = []
          var tool = []
          this.setResource(this.dataInfo, resource, tool)
          temp = resource
        } else if (this.waitTasks.isEdit == 7 || (this.waitTasks.task_def_key == '_15sontool' && this.serviceType ===
            'entry')) {
          var resource = []
          var tool = []
          this.setResource(this.dataInfo, resource, tool)
          temp = tool
        } else if (this.waitTasks.isEdit == 9 || (this.waitTasks.task_def_key == "_3" && this.serviceType ===
            'resourceAllo')) {
          if (this.dataInfo.resourceList.length > 0) {
            var resource = []
            var tool = []
            this.setResource(this.dataInfo, resource, tool)
            temp = resource
          } else if (this.dataInfo.toolList.length > 0) {
            var resource = []
            var tool = []
            this.setResource(this.dataInfo, resource, tool)
            temp = tool
          } else if (this.dataInfo.severList.length > 0) {
            this.dataInfo.severList.some(item => {
              if (item.check) {
                var t = {
                  alloId: item.id,
                  quantity: item.quantitys,
                  serviceId: item.severId
                }
                temp.push(t)
              }
            })
          } else if (this.waitTasks.isEdit == 21) {
            var temp = {
              alloId: 0,
              spContent: {
                etlpath: "",
                etlaccount: "",
              }
            }
            if (this.$parent.$refs.apply.dataInfo.toolList) {
              var tempaaa = JSON.parse(JSON.stringify(this.$parent.$refs.apply.dataInfo.toolList))
              console.log("temp ==========>", tempaaa)
              tempaaa.some(item => {
                temp.alloId = item.id
                temp.spContent.etlpath = this.dataEtlInfo.etlpath
                temp.spContent.etlaccount = this.dataEtlInfo.etlaccount

                // item.spContent.actTime = new Date(item.spContent.actTime).getTime()/1000
                // item.spContent.privateTransmisMode = JSON.stringify(item.spContent.privateTransmisMode)
                // item.spContent.publicTransmisMode = JSON.stringify(item.spContent.publicTransmisMode)
                // temp.spContent = item.spContent
              })

            }

            this.$set(this.handleInfo.content, "object", temp)
          } else if (this.waitTasks.isEdit == 22) {
            var temp = {
              alloId: 0,
              spContent: {
                customData: []
              }
            }
            if (this.$parent.$refs.apply.dataInfo.toolList) {
              var tempaaa = JSON.parse(JSON.stringify(this.$parent.$refs.apply.dataInfo.toolList))
              console.log("temp ==========>", tempaaa)
              tempaaa.some(item => {
                temp.alloId = item.id
                temp.spContent.customData = item.datas

                // item.spContent.actTime = new Date(item.spContent.actTime).getTime()/1000
                // item.spContent.privateTransmisMode = JSON.stringify(item.spContent.privateTransmisMode)
                // item.spContent.publicTransmisMode = JSON.stringify(item.spContent.publicTransmisMode)
                // temp.spContent = item.spContent
              })

            }

            this.$set(this.handleInfo.content, "object", temp)
          }
        } else if (this.waitTasks.isEdit == 13) {
          this.dataInfo.severList.some(item => {
            if (item.check) {
              var t = {
                alloId: item.id,
                quantity: item.quantitys,
                serviceId: item.severId
              }
              temp.push(t)
            }
          })
        } else if (this.waitTasks.isEdit == 20) {

          var temp = {
            spContent: {
              alloId: 0,
              fanTeamName: "",
              fanTeamLabel: ""
            }

          }
          this.dataInfo.toolList.some(item => {
            temp.spContent.alloId = item.id
            temp.spContent.fanTeamName = this.openApiInfo.fanTeamName
            temp.spContent.fanTeamLabel = this.openApiInfo.fanTeamLabel
          })

          this.$set(this.handleInfo.content, "object", temp)
        } else if (this.waitTasks.isEdit == 21) {
          var temp = {
            resource: [],
            tools: [],
            spContent: {
              alloId: 0,
              etlPath: "",
              etlAccount: "",
            }
          }
          if (this.dataInfo.toolList.length > 0) {
            console.log("this.dataInfo.toolList = ", this.dataInfo.toolList)
            this.dataInfo.toolList.forEach(tool => {
              if (tool.check) {
                var t = {
                  alloId: tool.id,
                  quantity: 1,
                  serviceId: tool.toolId,
                  "unit": ""
                }
                temp.tools.push(t)
                temp.spContent.alloId = tool.id
                temp.spContent.etlPath = this.dataEtlInfo.etlPath
                temp.spContent.etlAccount = this.dataEtlInfo.etlAccount
                tool.resourceProgress.forEach(item => {
                  if (item.check) {
                    var t = {
                      "alloId": item.id,
                      "quantity": item.resourcetype == 4 || item.resourcetype == 1 || item.resourcetype ==
                        3 ? 1 : item.quantity,
                      "serviceId": item.serviceId,
                      "unit": item.unit
                    }
                    temp.resource.push(t)
                  }
                })
              }
            })
          }
          this.$set(this.handleInfo.content, "object", temp)
        } else if (this.waitTasks.isEdit == 22) {
          var temp = {
            spContent: {
              alloId: 0,
              customData: []
            }
          }
          if (this.$parent.$refs.apply.dataInfo.toolList) {
            var tempaaa = JSON.parse(JSON.stringify(this.$parent.$refs.apply.dataInfo.toolList))
            tempaaa.some(item => {
              temp.spContent.alloId = item.id
              temp.spContent.customData = this.allEtlDataList
            })
          }

          this.$set(this.handleInfo.content, "object", temp)
        } else if (this.waitTasks.isEdit == 24) {
          var temp = {
            resource: [],
            tools: [],
            servers: [],
            spContent: {}
          }
          var resource = []
          var tool = []
          var data = this.dataInfo

          this.setResource(data, resource, tool)
          temp.resource = resource
          temp.tools = tool

          data.toolList.some(item => {
            if (item.resourceProgress) {
              item.resourceProgress.forEach(t1 => {
                var t = {
                  "alloId": t1.id,
                  "quantity": t1.resourcetype == 4 || t1.resourcetype == 1 || t1.resourcetype ==
                    3 ? 1 : t1.quantity,
                  "serviceId": t1.serviceId,
                  "unit": t1.unit
                }
                temp.resource.push(t)
              })
            }
          })
          if (this.dataInfo.severList.length > 0) {
            this.dataInfo.severList.some(item => {
              if (item.check) {
                var t = {
                  alloId: item.id,
                  quantity: item.quantitys,
                  serviceId: item.severId
                }
                temp.servers.push(t)
              }
            })
          }
          this.$set(this.handleInfo.content, "object", temp)
        }


        if (temp.length != 0) {
          this.handleInfo.content.object = temp
        }

      },
      setResource(data, resource, tool) {
        console.log("data.toolList------>", data.toolList)
        data.resourceList.some(item => {
          if (item.check) {
            var t = {
              "alloId": item.id,
              "quantity": item.resourcetype == 4 || item.resourcetype == 1 || item.resourcetype ==
                3 ? 1 : item.quantity,
              "serviceId": item.serviceId,
              "unit": item.unit
            }
            resource.push(t)
          }
        })
        data.toolList.some(item => {
          if (item.check) {
            var t = {
              alloId: item.id,
              quantity: 1,
              serviceId: item.toolId,
              "unit": ""
            }
            tool.push(t)
          }
        })
      },
      //校验提交时业务信息
      validateSubmintInfo() {
        console.log("------------>validateSubmintInfo", this.isDelegate, this.handleName.length,
          this.handleInfo.nextOperator.id, this.handleInfo.operation)
        var isSubmit = true
        var ifHandleIP = false;
        console.log('111')
        if (this.serviceType === "vip" && this.operation === "yes" && this.waitTasks.isEdit == 4) {
          console.log('222')
          var l = this.objList.length;
          for (let index = 0; index < this.objList.length; index++) {
            var temp = this.$refs['vipTable'][index].getVIP()
            for (var i = 0; i < temp.length; i++) {
              if (temp.ip === "" || temp.ip === null || temp.ip === undefined || temp.ipFlag) {
                ifHandleIP = true;
              }
            }
            this.object.push(temp)
          }
          // this.object = this.$refs.vipTable.getVIP();
          // console.log('this.object::',this.object)
          // for (var i = 0; i < this.object.length; i++) {
          //   if (this.object.ip === "" || this.object.ip === null || this.object.ip === undefined || this
          //     .object.ipFlag) {
          //     ifHandleIP = true;
          //   }
          // }
          // console.log('333')
        }

        if (this.isDelegate != 1 && this.handleName.length > 0) {
          console.log("======222222======");
          if (this.operation == 'sign' && this.handleInfo.signIds.length == 0) {
            isSubmit = false
            this.$Message.error('请选择下一步处理人！');
            this.handleLoading = false
            return isSubmit
          } else if (this.operation != 'sign' && (this.handleInfo.nextOperator.id == undefined || this.handleInfo
              .nextOperator
              .id === "")) {
            isSubmit = false
            this.$Message.error('请选择下一步处理人！');
            this.handleLoading = false
            return isSubmit
          }
        }

        if (ifHandleIP && this.handleInfo.operation === 'yes') {
          isSubmit = false
          this.$Message.error('浮动IP格式不规范或未填写！');
          this.handleLoading = false
        } else if (this.handleInfo.operation != 'no' && ((this.serviceType === 'hightAuthoritys' && this.taskDefKey ===
            '_03') || (this.serviceType === 'entry' && this.taskDefKey === '_04') || this.waitTasks.isPrint == '1') &&
          this.handleInfo.files.length == 0) {
          console.log("======要打印啊啊啊啊======");
          isSubmit = false
          this.$Message.error('请打印后签字上传附件！');
          this.handleLoading = false
        }
        if (this.isEdit == 20) {
          if (!this.openApiInfo.fanTeamLabel || !this.openApiInfo.fanTeamName) {
            isSubmit = false
            this.$Message.error('请填写实际分配团队！');
          }
        }
        if (this.isEdit == 21) {
          if (!this.dataEtlInfo.etlPath) {
            isSubmit = false
            this.$Message.error('请填写采集数据目录！');
          } else if (!this.dataEtlInfo.etlAccount) {
            isSubmit = false
            this.$Message.error('请填写分配账号！');
          }
        }
        if (this.isEdit == 22) {
          if (this.etlDataList.length == 0) {
            isSubmit = false
            this.$Message.error('请填写数据列表名称！');
          }

        }
        console.log("validateSubmintInfo------------->", isSubmit, this.waitTasks.isPrint)
        return isSubmit
      },

      // 处理成功，跳转页面
      submintSuccess(message) {
        this.$Message.success(message);
        setTimeout(() => {
          var index = -1;
          this.tabs.list.some((item, i) => {
            if (item.tabKey === this.tabs.tabsPage) {
              index = i
              return true
            }
          })
          this.tabs.tabsPage = 'processmain'
          this.tabs.list.splice(index, 1)
          this.handleLoading = false
          this.tabs.isEdit = true
          this.$store.commit("tabs", this.tabs);
        }, 1000);
      },
      // 获取执行操作集合
      getOperationList() {
        console.log("this.waitTasks---->", this.waitTasks)
        var that = this;
        var url = that.CONFIG.base_url_test + "/chooseList/" + this.reqId + "/" + this.waitTasks.taskId

        ajax.get({
          url: url,
          that: that,
          success: function(data) {
            console.log('getOperationList', data)
            if (data.length > 0) {
              that.operationList = data
              that.getHandleUserInfo(data[0].msgType)
            } else {
              that.$Message.error('暂无可选执行操作，请联系管理员！');
              that.showModal = false
            }
          }
        })
      },
      //设置下一步处理人的名称
      setNextOperator(value) {
        console.log("setNextOperator----->", value)
        if (this.operation == 'sign') {
          this.handleInfo.signIds = value
        } else {
          this.handleName.some(item => {
            if (item.id == value) {
              this.handleInfo.nextOperator = {
                id: value,
                userName: item.user_name
              }
            }
          });
        }
      },

      // 处理处理意见
      handleMessage(opOptions) {
        var newOptionName = this.operationList.find(e => e.msgType == opOptions).name + "; "
        if (this.lastOperation != "") {
          var oldOptionName = this.operationList.find(e => e.msgType == this.lastOperation).name + "; "
          if (this.handleInfo.message == "") {
            this.handleInfo.message = newOptionName
          } else if (this.handleInfo.message.indexOf(oldOptionName) == 0) {
            this.handleInfo.message = this.handleInfo.message.replace(oldOptionName, newOptionName)
          } else {
            this.handleInfo.message = newOptionName + this.handleInfo.message
          }
        } else {
          this.handleInfo.message = newOptionName
        }
        this.lastOperation = opOptions
      },
      //获取处理下一步的人员
      getHandleUserInfo(opOptions) {
        console.log('getHandleUserInfo', this.operation, opOptions)
        this.operation = opOptions
        this.handleName = []
        this.handleInfo.operation = opOptions
        this.handleMessage(opOptions)
        this.handleInfo.nextOperator = {
          id: "",
          userName: ""
        }
        var param = this.$parent.$refs.apply.getHandleUserParams(opOptions)
        console.log("---------param--------", param);

        var that = this;

        var url = ""
        if (opOptions === 'delegate') {
          url = that.CONFIG.base_url_test + "/delegate-can/" + this.waitTasks.taskId
        } else if (opOptions == 'complaint') {
          url = that.CONFIG.base_url_test + "/complaint-can/" + this.waitTasks.taskId
        } else {
          url = that.CONFIG.base_url_test + "/next-can/" + this.waitTasks.taskId
        }

        ajax.get({
          url: url,
          that: that,
          params: param,
          success: function(data) {
            that.nextCanInfo = data
            if (data.userList != null) {
              if (data.userList.length == 1) {
                that.handleInfo.nextOperator = {
                  id: data.userList[0].id,
                  userName: data.userList[0].user_name
                }
              }
              that.handleName = data.userList
            }
          }
        })
      },

      //设置账号申请相关
      submintSubAccount() {
        this.myObject.severs = this.$refs.sonAccount.severs;
        this.myObject.dbs = this.$refs.sonAccount.dbs;
        this.myObject.hadoops = this.$refs.sonAccount.hadoops;
        this.myObject.hftps = this.$refs.sonAccount.hftps;
        this.myObject.paas = this.$refs.sonAccount.paas;
        this.myObject.dacps = this.$refs.sonAccount.dacps;
        this.myObject.elseAuthes = this.$refs.sonAccount.elseAuthes;
        console.log("--------this.myObject", this.myObject);
      },
      getSonAccount() {
        if (this.waitTasks.isEdit == 10 || this.waitTasks.isEdit == 14) {
          this.accountInfo = this.$refs.sonAccount.sonAccount;
          //console.log("8888888888",this.$refs.sonAccount.sonAccount);
        }
        return this.accountInfo;
      },
      // 判断是否允许前往账号申请子工单
      ifNoToChildren() {
        return this.$refs.sonAccount.isNoToChildren;
      },
      addnetmap() {
        this.netmapobject.push({
          'ip': '',
          'serverType': '',
          'mapIp': '',
        })
      },
      deleteRow(roew, index) { //删除资源清单
        this.netmapobject.splice(index, 1);
      },
      // 新增vip
      addRow() {
        this.object.push({
          des: "",
          id: 0,
          ip: "",
          overId: 0
        });
      },
      // 删除vip
      remove(index) {
        this.object.splice(index, 1);
      },
    },
    computed: {
      showModal: {
        get: function() {
          return this.value;
        },
        set: function(value) {
          this.$emit('input', value);
        }
      },

    },
    props: {
      isEdit: {},
      param: {},
      value: {},
      processInfo: {}
    },
    watch: {
      value(newV) {
        if (newV) {
          this.tabs = this.$store.state.tabs
          this.getOperationList()
          // if (this.isEdit == 20) {
          //   this.seachAllTeamList("")
          // }
          // 暂时屏蔽
          // if (this.isEdit == 21) {
          //   this.getHistoryEtlPath()
          // }
        }
        if (this.isEdit == 20 && this.dataInfo.toolList && this.dataInfo.toolList.length > 0) {
          this.dataInfo.toolList.forEach(item => {
            if (item.spServiceType == "openApiPlatform") {
              var t = JSON.parse(JSON.stringify(item))
              this.openApiInfo = {
                fanTeamName: t.spContent.fanTeamName,
                fanTeamLabel: t.spContent.fanTeamLabel
              }
            }
          })
        }
      }
    }
  }
</script>
